package com.koron.common.web.personalizedconfiguration.controller;

import com.koron.bean.base.Response;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.common.web.personalizedconfiguration.bean.PersonalizedConfiguration;
import com.koron.common.web.personalizedconfiguration.service.PersonalizedConfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 性化配置管理{@code PersonalizedConfiguration} 控制层
 *
 * <p>主要提供：保存、查询功能</p>
 *
 * @author 朱超
 * @since 2021-09-08
 */
@RestController
@RequestMapping("/personalizedConfiguration")
@Api(tags = "个性化配置管理")
public class PersonalizedConfigurationController {

    private EamUser getCurrUser() {
        return ThreadLocalContext.get();
    }

    @Autowired
    private PersonalizedConfigurationService personalizedConfigurationService;

    /**
     * 保存单条数据：当没有该条数据的时候，新增该数据；当有该数据的时候，更新该数据
     *
     * @param personalizedConfiguration
     * @return Response
     * @version 1.0
     * @see Response
     */
    @PostMapping("save")
    @ApiOperation(value = "新增或者更新当前配置")
    public Response save(@RequestBody PersonalizedConfiguration personalizedConfiguration) {
        return ADOConnection.runTask(getCurrUser().getCurrDs(), personalizedConfigurationService, "save", Response.class, personalizedConfiguration);
    }

    /**
     * 根据查询条件获取对应的数据
     *
     * @param userId
     * @param page
     * @return Response
     * @version 1.0
     * @see Response
     */
    @GetMapping("getList")
    @ApiOperation(value = "根据对应的请求获取当前用户在当前水司的权限")
    public Response getList(@RequestParam(value = "userId") String userId, @RequestParam(value = "page", required = false) String page) {
        return ADOConnection.runTask(getCurrUser().getCurrDs(), personalizedConfigurationService, "getList", Response.class, userId, page);
    }

    @GetMapping("deleteById")
    @ApiOperation(value = "根据对应的id删除配置")
    public Response deleteById(@RequestParam(value = "id") String id){
        return ADOConnection.runTask(getCurrUser().getCurrDs(),personalizedConfigurationService,"deleteById",Response.class,id);
    }

}
